﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Microsoft.Practices.Unity;
using VLUSM_BusinessLogic;
using VLUSM_BusinessLogic.DataTransferObjects;

namespace VLUSM_Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "UserAccountService" in code, svc and config file together.
    public class UserAccountService : IUserAccountService
    {
        IUnityContainer container;
        UserAccountManager manager;

        public UserAccountService()
        {
            container = new UnityContainer();
            manager = container.Resolve<UserAccountManager>();
        }

        public UserDTO GetUserByID(int IDFilter)
        {
            return manager.GetUserByID(IDFilter);
        }

        public UserDTO GetUserByTenTaiKhoan(string TenTaiKhoanFilter)
        {
            return manager.GetUserByTenTaiKhoan(TenTaiKhoanFilter);
        }

        public UserDTO GetUserByUserNamePassword(string username, string password)
        {
            try
            {
                return manager.GetUserByUserNamePassword(username, password);
            }
            catch (Exception)
            {
                throw new FaultException("Đăng nhập thất bại");
            }
        }

        public void UpdateUserAccount(UserDTO objdto)
        {
            manager.UpdateUserAccount(objdto);
        }

        public void ChangePassword(int ID, string password)
        {
            manager.ChangePassword(ID, password);
        }

        public bool Validate(string username, string password)
        {
            return manager.Validate(username, password);
        }
    }
}
